<?php

require('init.php');

$title = 'Source: ' . htmlspecialchars($sourcefile);
require(LIBWWWDIR . '/header.php');
require(LIBWWWDIR . '/highlight.php');

if ( !isset($_REQUEST['pid']) && !isset($_REQUEST['cid']))
	header('Location: index.php');

if ( empty($_REQUEST['pid']) || empty($_REQUEST['cid']))
	header('Location: index.php');


$probid = @$_REQUEST['pid'];
$cid = @$_REQUEST['cid'];

//buscar sc solution en db2
$codes = get_source('0', $probid, $cid, $conn_db2);
//buscar nombre del problema
$prob_name =get_name($probid, "problem", $conn_db2);

echo "<h1> Solutions for: ".$prob_name[0]."</h1>\n\n";

echo "<table class=\"list sortable\">\n<thead><th scope=\"col\">team</th>".
	"<th scope=\"col\">hora_submit</th><th scope=\"col\">language</th>";		
$iseven = false;

for($i=1; $i<=$codes[0]; $i++)
{
	$link = '<a href="source_code.php?id='.$codes[$i]['scid'].'&time='.
	urlencode($codes[$i]['submittime']).'">';
	//buscar nombre del team
	$team_name = get_name($codes[$i]['teamid'], "team", $conn_db2);
	echo '<tr class="' .( $iseven ? 'roweven': 'rowodd' ) .(!$codes[$i]['enabled'] ? ' disabled' :'') .
		($codes[$i]['cid'] == $cid ? ' highlight':'') . '">' .
		"<td>" .$link .$team_name[0]."</a></td>\n" .
		"<td title=\"" . htmlspecialchars($codes[$i]['submittime']) ."\">" .
		$link.$codes[$i][submittime]."</a></td>\n".
		"<td title=\"". htmlspecialchars($codes[$i]['langid']) ."\">" .
		$link.$codes[$i][langid]."</a></td>\n";
		$iseven = ! $iseven;
		// display an unfreeze scoreboard button, only for the current
		// contest (unfreezing undisplayed scores makes no sense) and
		// only if the contest has already finished, and the scores have
		// not already been unfrozen.
		echo "<td>";
	if ( $codes[$i]['cid'] == $cid && isset($codes[$i]['freezetime']) ) 
	{
		echo "<input type=\"submit\" name=\"unfreeze[" .$codes[$i]['cid'] .
			"]\" value=\"unfreeze scoreboard now\"" ;
		$now = now();

		if ( difftime($codes[$i]['endtime'],$now) > 0 ||
		(isset($codes[$i]['unfreezetime']) && difftime($codes[$i]['unfreezetime'],$now) <= 0) )
		{
			echo " disabled=\"disabled\"";
		}
		echo " />";
	}
		echo "</td>\n</tr>\n";
}
echo "</tbody>\n</table>\n</form>\n\n";

require(LIBWWWDIR . '/footer.php');
?>
